package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import org.come.thread.TimeControlRunnable;
import org.come.until.FormsManagement;
import org.come.until.ScrenceUntil;
import org.come.until.Util;

import com.tool.btn.AntiPluginBtn;

public class AntiPluginJpanel extends JPanel {	
	private String value="大";
	private int sum;//错误次数  
	private AntiPluginBtn[] btns;
	public AntiPluginJpanel() {
		this.setPreferredSize(new Dimension(600, 200));
		this.setLayout(null);
		this.setBackground(new Color(0,0,0,0));
		btns=new AntiPluginBtn[4];
        for (int i = 0; i < btns.length; i++) {
        	btns[i]=new AntiPluginBtn("inkImg/hongmu/2/antipluginbtn"+(i+1)+".png", 1,i==0?"大":i==1?"话":i==2?"西":"游",this);
        	btns[i].setBounds(39+i*133, 66, 123, 127);
        	this.add(btns[i]);
		}
	}
	/**显示*/
	@Override
	public void show(){
		if (FormsManagement.getframe(69).isVisible()) {
			return;
		}
		FormsManagement.getframe(69).setBounds(Util.random.nextInt(ScrenceUntil.Screen_x-600),Util.random.nextInt(ScrenceUntil.Screen_y-200), 600, 200);
		TimeControlRunnable.JBTime=150000;
		sum=0;
		int i=Util.random.nextInt(4);
		value=i==0?"大":i==1?"话":i==2?"西":"游";
		FormsManagement.showForm(69);
	}
	/**正确*/
	public void correct(){
		TimeControlRunnable.JBTime=0;
		FormsManagement.HideForm(69);
	}
	/**选错*/
	public void error(){
		sum++;
		if (sum>=3) {
			System.exit(0);
			return;
		}
		int i=Util.random.nextInt(4);
		value=i==0?"大":i==1?"话":i==2?"西":"游";
	}
	/**超时*/
	public void overtime(){
		System.exit(0);
	}
	private ImageIcon icon;
	private Font font = new Font("宋体", Font.PLAIN, 16);
	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		// 画出背景图(npc聊天背景)
		if (icon==null) {
			icon=new ImageIcon("inkImg/hongmu/2/95_png.xy2uiimg.npctalk.png");
		}
		g.drawImage(icon.getImage(), 0, 0, 600, 200, this);
		g.setFont(font);
		g.setColor(Color.white);
		
		g.drawString("请选择下方“", 30, 37);
		g.drawString("”字图标,", 142, 37);
		g.drawString("剩余时间:", 30, 57);
		g.setColor(Color.green);
		g.drawString(value, 126, 37);
		g.setColor(Color.red);
		g.drawString(TimeControlRunnable.JBTime/1000+"s", 120, 57);	
		g.drawString("您的信任与支持，是我们前进最大的动力！", 238, 37);
		if (sum!=0) {
			g.drawString("你已经选错"+sum+"次,选错3次关闭游戏", 238, 57);
		}
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	
}
